package model;
import java.util.ArrayList;
import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import model.base.BaseDaliyRecord;

@SuppressWarnings("serial")
public class DaliyRecord extends BaseDaliyRecord<DaliyRecord> {
    public static final DaliyRecord dao = new DaliyRecord().dao();
    

	public DaliyRecord findFirstByStationIdAndDaliyItemsId(Long stationId , Long daliyItemsId){
        return this.findFirst(" SELECT tdr.* FROM t_daliy_record tdr WHERE tdr.stationId = ? AND tdr.daliyItemsId = ?  ORDER BY tdr.createTime DESC LIMIT 1 " , stationId , daliyItemsId);
    }
	
	public List<Record> findByRecordsId(Long recordsId){
        return Db.find(" SELECT tdi.duration , tdi.title , tdi.content , tdr.daliyItemsId FROM t_daliy_record tdr LEFT JOIN t_daliy_items tdi ON tdi.id = tdr.daliyItemsId WHERE tdr.recorderId = ? ORDER BY tdi.orderNum " , recordsId);
    }

	public List<Record> findByRecorderId(Long recorderId){
        return Db.find(" SELECT tdr.daliyItemsId , tdi.duration FROM t_daliy_record tdr LEFT JOIN t_daliy_items tdi ON tdi.id = tdr.daliyItemsId WHERE tdr.recorderId = ?  " , recorderId);
    }
	
	public List<Record> findRecords(DaliyRecords daliyRecords) {
		if (null == daliyRecords) {
			return new ArrayList<Record>();
		}
		return this.findByRecorderId(daliyRecords.getId());
	}
}
